package com.clear.company.generator.code;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;

import java.util.List;

/**
 * @auther: 黄树伟
 * @date: 2022/9/3
 * @description:
 */
public class MyAutoGenerator extends AutoGenerator {

    @Override
    protected List<TableInfo> getAllTableInfoList(ConfigBuilder config) {
        List<TableInfo> tableInfos = super.getAllTableInfoList(config);
        tableInfos.forEach(t -> {
            t.getFields().forEach(f -> {
                if (StringUtils.isNotBlank(f.getComment())) {
                    String comment = f.getComment();
                    comment = comment.replaceAll("\n", "").replaceAll("\r", ""); // 注意，替换换行符
                    f.setComment(comment);
                }
            });
        });
        return tableInfos;
    }
}
